#pragma once
#include "base/core/singleton.h"
#include "Common/ComTypeDefine.h"
#include "Common/CharacterDefine.h"

class AttrMgr : public ManualSingleton < AttrMgr >
{
	friend class ManualSingleton < AttrMgr > ;

public:
	typedef std::vector<uint32_t> VecAttr;
	typedef std::unordered_map<uint32_t, VecAttr> AttrVecMap;
	typedef std::unordered_map<uint32_t, uint32_t> mapAttr;
	typedef std::unordered_map<uint32_t, mapAttr> AdvAttrMap;
	typedef std::unordered_map<uint32_t, AdvAttrMap > profAdvAttrMap;
	typedef std::unordered_map<uint32_t, AttrVecMap > profRelationAdvMap;
	typedef std::unordered_map<uint32_t, uint32_t> buffAttrMap;
	typedef std::unordered_map<uint32_t, std::string> CurrencyNameMap;

protected:
	//******************玩家数据******************
	AttrVecMap			  m_mapPlayerAddFormula;//玩家加法计算属性公式关系表
	profAdvAttrMap		  m_mapTransAttrs;		//高级属性转换基础属性系数表
	AttrVecMap			  m_mapPAFinalFormula;  //玩家最终属性公式关系表

	CurrencyNameMap       m_mapCurrencyName;    //玩家货币属性对应名称

	uint32_t m_CAttrToPAttr[C_MAX]; 	//公共属性对用玩家属性id表

	//表格id属性与玩家属性Id转换表
	uint32_t m_CAttrToAdvAttr[C_MAX];   //公共属性对应玩家高级属性id表
	uint32_t m_PAttrBroadCast[P_MAX];	//玩家广播属性集合 (0:非广播属性，1:广播属性)

	//******************怪物数据******************
	uint32_t m_CAttrToMAttr[C_MAX]; 	//公共属性对应怪物属性id表
	uint32_t m_MAttrBroadCast[M_MAX]; //怪物 广播属性集合 (0:非广播属性，1:广播属性)
	AttrVecMap			  m_mapMonsterAddFormula;//怪物加法计算属性公式关系表
	AttrVecMap			  m_mapMAFinalFormula;  //怪物最终属性公式关系表
	AttrVecMap			  m_mapPlayerAddFormulaHasPercent; //带有百分比的属性，抽出来
	AttrVecMap			  m_mapMonsterAddFormulHasPercent; //怪物带有百分比
public:
	bool Init();   //初始化
	bool UnInit();
	//******************属性注册******************
	//总接口
	void InitPlayerAttr();
	void InitMonsterAttr();
	void InitCurrencyName();
	//************************************

	//******************模块属性注册******************
	//玩家
	void InitPlayerAdvanceAttr();
	void InitPlayerBaseAttr();
	void InitPlayerSynAttr();

	//怪物
	void InitMonsterBaseAttr();
	void InitMonsterSynAttr();

	//******************模块配置表相关属性处理******************
	//玩家
	void InitAdvCfgIdTransToPAttr();		//高级属性
	//******************属性公式注册******************
	//玩家
	void RegisterPAFormula(uint32_t attrType, uint32_t PANum);
	void HandlePAddFormula();

	//怪物
	void RegisterMAFormula(uint32_t attrType, uint32_t MANum);
	void HandleMAddFormula();
	
	//******************属性外部调用接口******************
	//玩家
	uint32_t GetPAttr(uint32_t CAttrNum);
	uint32_t GetCAttrNum(uint32_t PAttrNum);
	uint32_t GetPlayerFightModlePAttr(enFightAttrModule modleID,uint32_t CAttrNum);
	VecAttr* GetPAddAtrrsFormula(uint32_t PAttrNum);
	VecAttr* GetPAddAtrrsFormulaHasPer(uint32_t PAttrNum);
	VecAttr* GetPAFinalFormula(uint32_t PAttrNum);
	mapAttr* GetAdvanceAttrsAgrs(uint32_t playerProf, uint32_t PAttrNum);
	//uint32_t GetBuffFixAttr(uint32_t CAttrNum);
	//uint32_t GetBuffPercentAttr(uint32_t CAttrNum);
	//获取buff对应的c属性
	uint32_t GetBuffCNumAttr(uint8_t creatureType, uint32_t CAttrNum);
	uint32_t GetSKillCNumAttr(uint8_t creatureType, uint32_t CAttrNum);
	uint32_t GetLevCNumAttr(uint8_t creatureType, uint32_t CAttrNum);
	uint32_t GetMonsterLevMNumAttr(uint32_t CAttrNum);
	//某个职业的，记录能改变该属性的属性集合
	void  GetAdvanceAttrsBeAdd(uint32_t playerProf, uint32_t PAttrNum, mapAttr & tmpVecAttr);
	bool  IsBroadcastPAttr(uint32_t PAttr) const;

	const char* GetCurrencyName(uint32_t CAttr);


	//获取属性区间
	uint32_t GetTitlePNumStartIndex();
	uint32_t GetTitlePNumEndIndex();
	uint32_t GetEquipPNumStartIndex();
	uint32_t GetEquipPnumEndIndex();

	//怪物
	uint32_t GetMAttr(uint32_t CAttrNum);
	bool  IsBroadcastMAttr(uint32_t MAttr) const;
	VecAttr* GetMAFinalFormula(uint32_t PAttrNum);
	VecAttr* GetMAddAttrsFormula(uint32_t PAttrNum);
	//是否是允许负数
	bool IsCanNegativeMAttr(uint32_t MAttr);
	VecAttr* GetMAddAtrrsFormulaHasPer(uint32_t PAttrNum);
	AttrMgr();
	~AttrMgr();
};
#define g_MakeAttrMgr() (AttrMgr::Instance())
#define g_GetAttrMgr()  (AttrMgr::GetInstance())
#define g_DelAttrMgr()  (AttrMgr::Destroy())


